﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
 <div class="navbox">
	<div class="globalnav"> 
	    <a href="<%=request.getContextPath()%>/shopper/list" class="ed">
	    <span>进店统计</span>
	    </a> 
	    <a href="<%=request.getContextPath()%>/user/list">
	    <span>账号管理</span>
	    </a> 
    </div>
    <div class="subnav">
    	<a href="<%=request.getContextPath()%>/shopper/list" >
    		<span>今日进店</span>
    	</a>
    	<span class="line">|</span> 
   		<a href="<%=request.getContextPath()%>/shopper/query" class="ed">
    		<span>进店统计</span>
    	</a>
    </div>
  </div>

  <!--     主体从这开始    -->
  <div class="container">
    <h2 class="tit">
    	<a href="${ctx}/shopper/query">进店查询</a>
   		<a href="${ctx}/shopper/weekreport" class="current">周报表</a>
   		<a href="">月报表</a>
    </h2>
     <table class="global_table" cellpadding="0" cellspacing="0"> 
       <tr>
        <th class="width135">进店时间(月份)：</th>
        <td class="width100">
        	<select onchange="showWeek();" id="month">
        		<option>1</option>
        		<option>2</option>
        		<option>3</option>
        		<option>4</option>
        		<option>5</option>
        		<option>6</option>
        		<option>7</option>
        		<option>8</option>
        		<option>9</option>
        		<option>10</option>
        		<option>11</option>
        		<option>12</option>
        	</select>
        	</td>
        	<td>
        	&nbsp;&nbsp;&nbsp;&nbsp;
        	<div class="week"  id="week_div">
    			<%--<a href="<%=request.getContextPath()%>/shopper/list" class="ed">
    			<span id="week_1">第一周报表()</span>
    			</a>
    			
    			<span class="line">|</span>
    			 
   				<a href="<%=request.getContextPath()%>/shopper/query" class="ed">
    			<span>第二周报表</span>
    			</a>
    			
    			
    		--%></div>
        </td>
      </tr>
    </table> 
  
    <br/><br/>
    
    <div class="receipt_result receipt_result4" align="center" style="margin-top:5px;">
    	<p>
    		<span>进店统计 (${user.store})<em id="e"></em> </span>
    	</p>
    	<p>
	   		进店总人数: ${allEnterCount}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总试穿人数：${allTryonCount}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总成交人数：${allTradeCount}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总试穿率：${tryonPre}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总成交率：${tradePre}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总成交金额：${allTradeAmount}
	   		&nbsp;&nbsp;&nbsp;&nbsp;
	   		总客单价：${amountPre}
   		</p>
   		</div>
   		<br/><br/>
   		 <c:if test="${valueList.valueListInfo.totalNumberOfEntries>0}">
   <vlh:root value="valueList" url="?" includeParameters="#" > 
   <%@ include file="../commons/valuelist_paging.jsp" %>
	<div class="scroll_tableresult">
    <table class="global_vtable" cellpadding="0" cellspacing="0">
     <thead>
      <tr>
        <th>进店时间</th>
        <th>进店人数</th>
        <th>试穿人数</th>
        <th>成交人数</th>
        <th>接待人</th>
        <th>新/老顾客</th>
        <th>经营/自然进店</th>
        <th>进店结果</th>
        <th>导致结果原因分析</th>
        <th>成交金额</th>
      </tr>
      </thead>
       <tbody>
    	<vlh:row bean="shopper" > 
      	<tr>
       	 	<td><fmt:formatDate value="${shopper.map.enter_date}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
        	<td>${shopper.map.enter_count}</td>
        	<td>${shopper.map.tryon_count}</td>
        	<td>${shopper.map.trade_count}</td>
        	<td>${shopper.map.receptionist_id}</td>
        	<td>${shopper.map.into_type}</td>
        	<td>${shopper.map.new_or_old}</td>
        	<td>${shopper.map.result}</td>
        	<td>${shopper.map.reason}</td>
        	<td>${shopper.map.trade_amount}</td>
      	</tr>
      	</vlh:row>
      	</tbody>
    </table>
    </div>
    <%@ include file="../commons/valuelist_paging.jsp" %>
    </vlh:root>
    </c:if>
    <c:if test="${valueList.valueListInfo.totalNumberOfEntries<=0}">
		<div class="receipt_result btncenter font14">
			没有符合条件的查询结果！
		</div>
	</c:if>
   	</div>
    
  <!--     主体 end    -->
  <script type="text/javascript">
  	function showWeek(){
		var month = $("#month").val();
		var currDt = getFirstWeek(month);
		nextWeek(month,currDt,2);
				
	}
	//下一周周末的日期
	function nextWeek(month,currDt,i){
		var lastDate = new Date(currDt.getFullYear(),month,getLastDay(currDt.getFullYear(),month-1));
		if((currDt.getDate()+7)<=getLastDay(currDt.getFullYear(),month-1)){
			var content = $("#week_span").text();
			
			var start = new Date();
			start.setFullYear(currDt.getFullYear());
			start.setMonth(currDt.getMonth());
			start.setDate(currDt.getDate());
			
			currDt.setDate((currDt.getDate()+7));
			var content1 = $("#week_span1").text();
			
			
			$("#week_div").append("<span class='line'>|</span><a href='<%=request.getContextPath()%>/shopper/weekreport?"
					+"startDate="+start.getFullYear()+"-"+(start.getMonth()+1)+"-"+start.getDate()
					+"&endDate="+currDt.getFullYear()+"-"+(currDt.getMonth()+1)+"-"+currDt.getDate()
					+"' class='ed'><span>第"+i+"周报表</span></a>");
			
			nextWeek(month,currDt,++i);
		}else{
			currDt.setDate((currDt.getDate()+1));
			$("#week_div").append("<span class='line'>|</span><a href='<%=request.getContextPath()%>/shopper/weekreport?"
					+"startDate="+start.getFullYear()+"-"+(start.getMonth()+1)+"-"+start.getDate()
					+"&endDate="+currDt.getFullYear()+"-"+(currDt.getMonth()+1)+"-"+lastDate.getDate()
					+"' class='ed'><span>第"+i+"周报表</span></a>");
		}
	}
	
	//第一周周末的日期
	function getFirstWeek(month){
		var currDt = new Date();
		currDt.setMonth(month-1);//设置
		currDt.setDate(1);//设置位该月一号
		var dw = currDt.getDay();//获取当前时间是星期几
		
		var start = new Date();
		start.setFullYear(currDt.getFullYear());
		start.setMonth(currDt.getMonth());
		start.setDate(currDt.getDate());

		var smonth = start.getMonth()+1;
		if(smonth<10){
			smonth="0"+smonth;
		}

		var sdate = start.getDate();
		if(sdate<10){
			sdate="0"+sdate;
		}
		
		if(7-dw != 0){
			currDt.setDate(8-dw);
		}

		var emonth = currDt.getMonth()+1;
		if(emonth<10){
			emonth="0"+smonth;
		}

		var edate = currDt.getDate();
		if(edate<10){
			edate="0"+edate;
		}
		
		$("#week_div").empty();
		$("#week_div").append("<a href='<%=request.getContextPath()%>/shopper/weekreport?startDate="+start.getFullYear()+"-"+smonth
				+"-"+sdate+"&endDate="+currDt.getFullYear()+"-"+emon+"-"+currDt.getDate()+
				"' class='ed'><span>第1周报表</span></a>");
		
		return currDt;
	}

	 //是否为闰年
	 function isLeapYear(y) {
	  var isLeap = false;
	  if(y%4==0 && y%100!=0 || y%400==0) {
	   isLeap = true;
	  }
	  return isLeap;
	 }
		

	 //每月最后一天
	 function getLastDay(y,m) {
	  	var lastDay = 28;
	  	m++;
	  	if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) {
	   		lastDay = 31;
	  	}
	  else if(m==4 || m==6 || m==9 || m==11) {
	   lastDay = 30;
	  }
	  else if(isLeapYear(y)==true) {
	   lastDay = 29;
	  }
	  return lastDay;
	 }
  </script>
</body>
</html>
